<template>
	<view class="page">
		<topVue :title="i18n.b1" :isRecord="true" path="../casting/record"></topVue>
		<view class="banner margin0 relative">
			<view class="flex align-center">
				<image src="../../static/coins/usdt.png" style="width: 86rpx; height: 86rpx;"></image>
				<view class="flex-column flex-1 flex-between" style="height: 86rpx; padding-left: 20rpx;">
					<view class="flex align-center">
						<text style="color: rgba(255,255,255,0.6); line-height: 1;">{{ i18n.b2 }}</text>
						<image src="../../static/checked.png" style="width: 56rpx; height: 28rpx; margin-left: 25rpx;" v-if="checked==1" @click="setAutoMint()"></image>
						<image src="../../static/check.png" style="width: 56rpx; height: 28rpx; margin-left: 25rpx;" v-else @click="setAutoMint()"></image>
					</view>
					<view class="using">{{ balance }}</view>
				</view>
			</view>
			<view class="flex absolute-center w100 padding-row30" style="bottom: 80rpx;">
				<view class="in" @click="show=true; type=0">
					<image src="../../static/in.png" style="width: 56rpx; height: 56rpx;"></image>
					<text style="font-size: 32rpx; color: #45F882; padding-left: 15rpx; font-weight: 600;">{{ i18n.b3 }}</text>
				</view>
				<view class="out" @click="show=true; type=1">
					<image src="../../static/out.png" style="width: 56rpx; height: 56rpx;"></image>
					<text style="font-size: 32rpx; color: #fff; padding-left: 15rpx; font-weight: 600;">{{ i18n.b4 }}</text>
				</view>
			</view>
		</view>

		<view class="castingVue margin50">
			<!-- <view class="casting flex-column flex-between">
				<view class="name">{{ i18n.b5 }}</view>
				<view class="num">{{ i18n.b6 }}：{{ quota.staticQuota1 }}</view>
				<view class="num">{{ i18n.b7 }}：{{ quota.rewardQuota1 }}</view>
				<view class="num">{{ i18n.b8 }}：{{ quota.remainQuota1 }}</view>
				<image src="../../static/casting.png" style="width: 260rpx; height: 52rpx;" @click="$tools.route('./doit', 1)"></image>
			</view>
			<view class="casting flex-column flex-between">
				<view class="name">{{ i18n.b15 }}</view>
				<view class="num">{{ i18n.b6 }}：{{ quota.staticQuota2 }}</view>
				<view class="num">{{ i18n.b7 }}：{{ quota.rewardQuota2 }}</view>
				<view class="num">{{ i18n.b8 }}：{{ quota.remainQuota2 }}</view>
				<image src="../../static/casting.png" style="width: 260rpx; height: 52rpx;" @click="$tools.route('./doit', 2)"></image>
			</view> -->
			<view class="casting flex-column flex-between">
				<view class="name">COO铸造</view>
				<view class="flex-between align-center">
					<text>额度：{{ quota.remainQuota1 }}</text>
					<image src="../../static/casting.png" style="width: 250rpx; height: 52rpx;" @click="$tools.route('./doit', 1)"></image>
				</view>
			</view>
			<view class="casting flex-column flex-between">
				<view class="name">CTO铸造</view>
				<view class="flex-between align-center">
					<text>额度：{{ quota.remainQuota2 }}</text>
					<image src="../../static/casting.png" style="width: 250rpx; height: 52rpx;" @click="$tools.route('./doit', 2)"></image>
				</view>
			</view>
			<view class="casting flex-column flex-between" v-if="status==1">
				<view class="name">CQO铸造</view>
				<view class="flex-between align-center">
					<text>额度：{{ quota.remainQuota3 }}</text>
					<image src="../../static/casting.png" style="width: 250rpx; height: 52rpx;" @click="$tools.route('./doit', 3)"></image>
				</view>
			</view>
		</view>

		<!-- 托管余额转入转出 -->
		<u-popup v-model="show" mode="center" @close="amount=''">
			<view class="langVue flex-between flex-column">
				<view class="lang flex-between flex-column align-center">
					<view class="title text-center">{{ type===0 ? "托管余额转入" : "托管余额转出"}}</view>
					<view class="inpVue flex-center align-center">
						<input type="text" placeholder="请输入数量" v-model="amount"/>
					</view>
					<view class="btn margin0" @click="submit()">
						<image src="../../static/wallet/btn.png" style="width: 100%; height: 100%;"></image>
					</view>
				</view>
				<view class="closeVue flex-center align-center" @click="show=false; amount='';">
					<image src="../../static/close.png" style="width: 58rpx; height: 58rpx;"></image>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				show: false,
				type: 0,  //0转入  1转出
				amount: "",
				checked: 0,
				balance: 0,
				quota: {},
				status: 0,
			}
		},

		async onShow() {
			await this.getInfo()
			await this.getLimit()
			await this.getStatus()
		},
		computed:{
			i18n() {
				return this.$t("message");
			}
		},

		methods: {
			async getLimit(){
				const result = await this.$request("/front/financial/mintQuota")
				if(result.code===0) {
					this.quota = result.data;
				}
			},

			async getInfo(){
				const result =  await this.$request("/front/financial/userHosting")
				if(result.code===0) {
					console.log(result)
					this.checked = result.data.autoMint
					this.balance = result.data.balance
				}
			},
			
			async getStatus(){
				const result = await this.$request("/front/financial/cqoOpen")
				if(result.code===0) {
					console.log(result)
					this.status = result.data
				}
			},

			// 托管余额转入转出
			async submit(){
				if(!this.amount || this.amount==0) return this.$u.toast(this.i18n.input)
				let url = ["/front/financial/transferIn","/front/financial/transferOut"][this.type]
				if(this.type===1 && this.balance < this.amount) return this.$u.toast(this.i18n.limit)
				if(this.type===1 && this.balance==0) return this.$u.toast(this.i18n.limit)
				const res = await this.$request(url, {amount: this.amount})
				if(res.code===0) {
					this.$u.toast(this.i18n.success)
					this.amount = ""
					this.show = false
					this.getInfo()
				}else {
					this.$u.toast(res.msg)
				}
			},

			// 设置自动铸造
			async setAutoMint(){
				const res = await this.$request("/front/financial/setAutoMint", {value: this.checked==1? 0 : 1})
				if(res.code===0) {
					this.$u.toast(this.i18n.success)
					this.getInfo()
				}else {
					this.$u.toast(res.msg)
				}
			}
		}
	}
</script>

<style lang="less" scoped>
	/deep/.u-mode-center-box {
		background-color: transparent !important;
	}
	/deep/.u-drawer-left {
		background-color: transparent !important;
	}
	.castingVue {
		width: 690rpx;
		// height: 217rpx;
		.casting {
			width: 100%;
			height: 180rpx;
			background: url("../../static/1.jpg") no-repeat;
			background-size: 100% 100%;
			padding: 30rpx;
			margin-top: 30rpx;
			.name {
				line-height: 1;
			}
			.num {
				font-weight: 400;
				font-size: 26rpx;
				line-height: 1;
			}
		}
	}
	.banner {
		width: 690rpx;
		height: 460rpx;
		background: url("../../static/casting_banner.png") no-repeat;
		background-size: 100% 100%;
		padding: 140rpx 0 0 70rpx;
		.using {
			font-weight: 600;
			font-size: 46rpx;
			color: #45F882;
			line-height: 1;
		}
		.in, .out {
			width: 50%;
			height: 56rpx;
			display: flex;
			justify-content: center;
			align-items: center;
		}
	}

	.langVue {
		width: 670rpx;
		height: 732rpx;
		padding: 52rpx 0 40rpx;
		box-sizing: border-box;
		.lang {
			width: 670rpx;
			height: 452rpx;
			background: url("../../static/lang_kuang.png") no-repeat;
			background-size: 100% 100%;
			padding: 60rpx 0 80rpx;
		}
		.title {
			font-size: 32rpx;
			font-weight: 600;
		}
		.inpVue {
			width: 80%;
			height: 100rpx;
			border: 1px solid #4C5B51;
			border-radius: 16rpx;
			input {
				width: 100%;
				height: 100rpx;
				color: #fff;
				padding-left: 20rpx;
				display: block;
				box-sizing: border-box;
			}
		}
		.btn {
			width: 327rpx;
			height: 90rpx;
		}
		.closeVue {
			width: 100%;
			height: 100rpx;
		}
	}
</style>
